package RestWS;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBElement;
import model.Customer;
import convert.CustomerBN;
import dao.CustomerDao;


@Path("/customerstore")
public class CustomerStoreResource {
	
	
	/*-------------------------------------------------------------------
	 * 
	 * 
	 *   Insert into Jsson -----
	 * 
	 *                 {
						 "id":20,
						 "name":"morad",
						 "address":"cantonment"
						}



	 * 
	 * 
	 *-----------------------------------------------------------------------*/
	
	
	
	
	

	@POST
	@Path("/save")
	@Consumes(MediaType.APPLICATION_JSON)
	public String  persistCustomer(CustomerBN customerBN)
	{
		try {
			
		
	//CustomerBN customerBN=jaxbcontent.getValue();
	Customer customer=new Customer();
	customer.setAddres(customerBN.getAddress());
	customer.setName(customerBN.getName());
		
	CustomerDao customerDao=new CustomerDao();
	customerDao.insertCustomer(customer);
	
		
		} catch (Exception e) {
			
			return "data not inserted";
			// TODO: handle exception
		}
		
		return "data  inserted is ok";
	}
	
	
	@PUT
	@Path("{ids}")
	@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public String  updateCustomers(CustomerBN jaxbcontent,@PathParam("ids") int ids)
	{
		
		System.out.println("update Customer  $$$$-****************----problem soleved");
		
		
		System.out.println(ids);
	
		
		return "data  update is ok";
	}
	


}
